
from pages.base_page import BasePage
from selenium.webdriver.common.by import By


class CustomerPage(BasePage):
    url = "/crm/index.php?m=customer"
    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')
    error_locator =(By.XPATH,"/html/body/div/form/fieldset/div[1]")
    add_customer_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div/a')  # 新建客户
    # 第一个客户
    first_customer_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    # 第二个客户
    second_customer_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(2) > td:nth-child(1) > input')
    # 批量操作
    batch_operation_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > ul > div > a')
    attention_locator = (By.LINK_TEXT, '批量关注')  # 批量关注
    I_am_concerned_locator = (By.LINK_TEXT, '我关注的')  # 我关注的
    delete_locator = (By.ID, 'delete')  # 批量删除
    share_locator = (By.ID, 'share')  # 批量共享
    software_testing_locator = (By.XPATH, '//*[@id="dialog-share"]/form/table/tbody/tr/td/ul/li[1]/a')  # 客户共享弹窗——软件测试部门
    choose_all_user_locator = (By.XPATH, '//*[@id="ta1"]/input')  # 全部选择
    # 确认共享
    notarize_share_locator = (By.XPATH, '//*[@id="dialog-share"]/form/table/tfoot/tr/td/input[1]')
    my_shared_locator = (By.LINK_TEXT, '我共享的')  # 视图——我共享的
    contacts_locator = (By.CSS_SELECTOR, 'body > div.container > div.page-header > ul > li:nth-child(3) > a')  # 联系人
    # 客户关怀
    customer_care_locator = (By.CSS_SELECTOR, 'body > div.container > div.page-header > ul > li:nth-child(4) > a')
    recycle_bin_locator = (By.CSS_SELECTOR,'body > div.container > p > a:nth-child(13)')    # 回收回收站按钮
    tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')  # 操作后提示

    def click_add_customer(self):
        """
        新建客户
        """
        self.find_element(self.add_customer_locator).click()

    def click_first_customer(self):
        """
        选中第一个客户
        """
        self.find_element(self.first_customer_locator).click()

    def click_second_customer(self):
        """
        选中第二个客户
        """
        self.find_element(self.second_customer_locator).click()

    def click_batch_operation(self):
        """
        点击批量操作
        """
        self.find_element(self.batch_operation_locator).click()

    def click_attention(self):
        """
        点击批量关注
        """
        self.find_element(self.attention_locator).click()

    def click_concerned(self):
        """
        点击视图——我关注的
        """
        self.find_element(self.I_am_concerned_locator).click()

    def click_share(self):
        """
        点击批量共享
        """
        self.find_element(self.share_locator).click()

    def click_delete(self):
        """
        点击批量删除
        """
        self.find_element(self.delete_locator).click()

    def click_software_testing(self):
        """
        客户共享弹窗——选择CEO
        """
        self.find_element(self.software_testing_locator).click()

    def click_choose_all(self):
        """
        选择全部选择
        """
        self.find_element(self.choose_all_user_locator).click()

    def click_notarize_share(self):
        """
        点击确认共享
        """
        self.find_element(self.notarize_share_locator).click()

    def click_my_shared(self):
        """
        视图——点击我共享的
        """
        self.find_element(self.my_shared_locator).click()

    def click_contacts(self):
        """
        点击联系人
        """
        self.find_element(self.contacts_locator).click()

    def click_recycle_bin(self):
        """
        点击回收站按钮
        """
        self.find_element(self.recycle_bin_locator).click()

    def click_customer_care(self):
        """
        点击客户关怀
        """
        self.find_element(self.customer_care_locator).click()
#返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text

#返回报错弹窗文本信息
    def get_error_text(self):
        return self.find_element(self.error_locator).text

